package com.bolt.admin.web.view.freemarker;

import com.alibaba.fastjson.JSON;
import com.bolt.admin.module.sys.service.MenuService;
import com.bolt.common.utils.SpringContextUtil;
import com.bolt.support.ui.tree.vo.UITreeNode;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/4/17.
 */
public class AuthMenuModel implements TemplateDirectiveModel {

    @Override
    public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
        MenuService menuService = SpringContextUtil.getBean(MenuService.class);
        List<UITreeNode> nodes = menuService.authUserMenu();
        environment.getOut().write( JSON.toJSONString(nodes));
    }
}

 